#include "system.h"
#include "SysTick.h"
#include "usart.h"
#include "led.h"
#include "stm32f1xx_hal.h"
#include "bsp_esp.h"
#include "bsp_device.h"

int main()
{
	char topic[50] = {0};
  char payload[100] = {0};
	
	
	HAL_Init();                     
	SystemClock_Init(RCC_PLL_MUL9); 
	SysTick_Init(72);
	USART1_Init(115200);
	LED_Init();
	init_device_state();
	while (1) 
		
	{
		if(USART1_RX_STA & 0x8000)
		{
			memset(payload, 0, sizeof(payload));
			esp8266_receive_msg((char *)USART1_RX_BUF,topic,payload);
			if(strcmp(payload, "ON") == 0)	set_led_state(LED1,ON);
			if(strcmp(payload, "OFF") == 0)	set_led_state(LED1,OFF);
			USART1_RX_STA=0;
		}

		HAL_GPIO_TogglePin(LED2_PORT,LED2_PIN);
		HAL_Delay(100);
	}
}
